package com.example.logistics_oa.controller;

import com.example.comment_oa.pojos.*;
import com.example.comment_oa.pojos_vo.BuTieChaXunVo;
import com.example.comment_oa.response.AjaxResponse;
import com.example.logistics_oa.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:员工薪资构成、职位对应补贴表
 * @Author:李博文
 * @Date:2022/10/17 17:35
 */
@RestController
@CrossOrigin
@RequestMapping("/logisticsOa")
public class EmployeeZhiWeiDuiyingBuTieController {

    @Autowired
    JobcorresSubsidyService jobcorresSubsidyService;

    @Autowired
    OvertimeBonusService overtimeBonusService;

    @Autowired
    BelateMoneyService belateMoneyService;

    @Autowired
    XgJiabanService xgJiabanService;

    @Autowired
    XgKaoqinService xgKaoqinService;

    @PostMapping("/zhiweiduiyingbutie")
    public AjaxResponse chakanquanbu(@RequestBody BuTieChaXunVo buTieChaXunVo){
        List<JobcorresSubsidy> jobcorresSubsidies = jobcorresSubsidyService.selectAll(buTieChaXunVo);
        return AjaxResponse.success(jobcorresSubsidies);
    }


    @GetMapping("/zhiweiduiyingbutie/jiaban")
    public AjaxResponse chakanjiaban(){
        List<OvertimeBonus> overtimeBonuses = overtimeBonusService.selectAll();
        return AjaxResponse.success(overtimeBonuses);
    }


    @GetMapping("/zhiweiduiyingbutie/chidao")
    public AjaxResponse chakanchidao(){
        List<BelateMoney> belateMonies = belateMoneyService.selectBelate();
        return AjaxResponse.success(belateMonies);
    }

    @PutMapping("/zhiweiduiyingbutie/xiugaiJiaBanStatus/{obId}")
    public AjaxResponse xiugaijiabanstaus(@PathVariable("obId")int obId, @RequestBody XgJiaban xgJiaban){
        overtimeBonusService.updaJiaBanStatus(obId);
        xgJiaban.setXgProperty("禁用项目");
        xgJiabanService.isnertJiLu(xgJiaban);
        return AjaxResponse.success();
    }
    @PutMapping("/zhiweiduiyingbutie/xiugaiJiaBanStatus2/{obId}")
    public AjaxResponse xiugaijiabanstaus2(@PathVariable("obId")int obId,@RequestBody XgJiaban xgJiaban){
        overtimeBonusService.updaJiaBanStatus2(obId);
        xgJiaban.setXgProperty("启用项目");
        xgJiabanService.isnertJiLu(xgJiaban);
        return AjaxResponse.success();
    }

    @PutMapping("/zhiweiduiyingbutie/JinYongChiDaoFaKuan/{blId}")
    public AjaxResponse JinYongChiDaoFaKuan(@PathVariable("blId")int blId, @RequestBody XgKaoqin xgKaoqin){
        xgKaoqin.setXgProperty("禁用项目");
        xgKaoqinService.isnertJiLu(xgKaoqin);
        belateMoneyService.updateJinYongFakuan(blId);
        return AjaxResponse.success();
    }

    @PutMapping("/zhiweiduiyingbutie/QiYongChiDaoFaKuan/{blId}")
    public AjaxResponse QiYongChiDaoFaKuan(@PathVariable("blId")int blId, @RequestBody XgKaoqin xgKaoqin){
        xgKaoqin.setXgProperty("启用项目");
        xgKaoqinService.isnertJiLu(xgKaoqin);
        belateMoneyService.updateQiYongFakuan(blId);
        return AjaxResponse.success();
    }

    @PutMapping("/zhiweiduiyingbutie/gaiedu/{obLimit}/{obId}")
    public AjaxResponse xiugaijiangjinedu(@PathVariable("obId")int obId,@PathVariable("obLimit") Double obLimit ,@RequestBody XgJiaban xgJiaban){
        if(xgJiaban.getXgBefore() < xgJiaban.getXgAfter()){
            xgJiaban.setXgProperty("上调");
        }else if(xgJiaban.getXgBefore() > xgJiaban.getXgAfter()){
            xgJiaban.setXgProperty("下降");
        }
        xgJiabanService.isnertJiLu(xgJiaban);
        overtimeBonusService.updaJiaBanJiangJin(obLimit, obId);
        return AjaxResponse.success();
    }

    @PutMapping("/zhiweiduiyingbutie/gaiFaKuan/{blMoney}/{blId}")
    public AjaxResponse xiugaijiangzhidaoFaKuan(@PathVariable("blId")int blId,@PathVariable("blMoney") Double blMoney ,@RequestBody XgKaoqin xgKaoqin){

        if(xgKaoqin.getXgBefore() < xgKaoqin.getXgAfter()){
            xgKaoqin.setXgProperty("上调");
        }else if(xgKaoqin.getXgBefore() > xgKaoqin.getXgAfter()){
            xgKaoqin.setXgProperty("下降");
        }
        xgKaoqinService.isnertJiLu(xgKaoqin);
        belateMoneyService.updateMoney(blMoney, blId);
        return AjaxResponse.success();
    }


}
